﻿// 大作业.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//

#include "pch.h"
#include <graphics.h>
#include<stdlib.h>
#include <conio.h>
#include<stdio.h>
#include<Windows.h>


#define applenum 10

//#pragma comment(lib,"Winmm.lib")
//put all below into a function ,and set up a choose 
//function to choose what funtion to execute???
IMAGE startbk;
IMAGE background;
IMAGE man1[2][5], man2[2][5];//1-->正常图，2--》遮罩图
IMAGE grass;

IMAGE tree2;//地图元素,//0是树，1是苹果
IMAGE tree2_b;
IMAGE tree1;//地图元素,//0是树，1是苹果
IMAGE tree1_b;

IMAGE apple1;
IMAGE apple1_b;

IMAGE trunk1;
IMAGE trunk1_b;
IMAGE trunk2;
IMAGE trunk2_b;

IMAGE choosebk;
IMAGE chooseblock;
IMAGE choosestick;
IMAGE GAMEOVER;
IMAGE BOSS;
IMAGE bossapple[10];
IMAGE bossapple_b[10];
IMAGE Baron_Nashor;
IMAGE warning1;
IMAGE warning2;
IMAGE bossapple1[10][4];
IMAGE bossapple_b1[10][4];

IMAGE bigtrunk;
IMAGE midtrunk;
//IMAGE sun;
//IMAGE sun_b;

IMAGE midapple;
IMAGE bigapple;
IMAGE midapple_b;
IMAGE bigapple_b;
IMAGE largeapple;
IMAGE largeapple_b;
IMAGE Baron_Nashorb;

IMAGE stab_b;
IMAGE stab;
IMAGE archivepoint;
IMAGE horizontaltrunk;
int treeleave1_x, treeleave1_y;
int treeleave2_x, treeleave2_y;
int treedeadline;
int startstick_x, startstick_y;//存档刺的位置
int startblock_x, startblock_y;//存档块的位置
int choosenum;
int i, j;//man move process,i==right,j==left
int direction;
int input[2];//to know if input exist
int man_x, man_y;
int man_tx, man_ty;
int grass_zy;
int g;//加速度
int man_vy;
int step_x, step_y;
int count;//按键计数器,用于控制按跳跃的次数，还不完善
int apple_x, apple_y;
int appledeadline;
//int passcount;//经过次数判定
//int Interface;
int manlen;
int manhigh;
int applelen;
int applehigh;
int gamestatus[3];//游戏状态,
int isdie;
int isfall;//树叶掉落；

int trunk1_x, trunk1_y;//树干
int trunk2_x, trunk2_y;//树干

int restart;
int treellen, treelhigh;//树叶长宽
int treetlen, treethigh;//树干长宽
int leave_trigger;
int apple_trigger;//触发掉落
int apple_trigger2;
int treeleave_vy;
int apple_vy;
int boss_trigger;//boss觉醒
int boss_x, boss_y;
int bossapple1_x[10], bossapple1_y[10];
int bossapple_x[10], bossapple_y[10];//第二波，也就是最开始的做的·一波
int bossapple1_vy[10];
int bossapple_vy[10];//第二波，也就是最开始的做的·一波
int countdown;
int frequency;//第二波
int frequency1;//第一波
int order;
int order1;
//判定苹果是否从地图外进入地图
int appear[10];
int appear1[10];
//boss的长，宽
int bossmouth;
int bosshigh;
//弹跳触发
int bouncetrigger[10];
int circulateswitch;
int count2;
//大树干的位置
int bigtrunk_x, bigtrunk_y;
int bigtrunklen, bigtrunkhigh;
//二维数组下标
int iapple;
//苹果变长的过程
int midtrunk_x, midtrunk_y;
int midtrunklen, midtrunkhigh;
int sun_x, sun_y;
int sunlen, sunhigh;
int applecount;
int appletri;
int bossapple_vx[10];
int point_x, point_y;
int point_vy;



void writerecordfile()//存档
{
	FILE*fp;
	/*fp = fopen(".\\gameRecord.dat", "w");*/
	fp = fopen("gameRecord.txt", "w");
	fprintf(fp, "%d%d", i, j);
	fprintf(fp, "%d", direction);
	fprintf(fp, "%d", input[0]);
	fprintf(fp, "%d", input[1]);
	fprintf(fp, "%d%d", man_x, man_y);
	fprintf(fp, "%d", grass_zy);
	fprintf(fp, "%d", g);
	fprintf(fp, "%d",man_vy);
	fprintf(fp, "%d%d", step_x, step_y);
	fprintf(fp, "%d", count);
	fprintf(fp, "%d%d", treeleave1_x, treeleave1_y);
	fprintf(fp, "%d%d", treeleave2_x, treeleave2_y);
	fprintf(fp, "%d%d", apple_x, apple_y);
	
	fprintf(fp, "%d", manlen);
	fprintf(fp, "%d", manhigh);
	

	fprintf(fp, "%d", treetlen);
	fprintf(fp, "%d", treethigh);
	fprintf(fp, "%d", treellen);
	fprintf(fp, "%d", treelhigh);
	fprintf(fp, "%d", treedeadline);
	fprintf(fp, "%d", appledeadline);
	fprintf(fp, "%d", trunk2_x);
	fprintf(fp, "%d", trunk2_y);
	fprintf(fp, "%d", trunk1_x);
	fprintf(fp, "%d", trunk1_y);
	fprintf(fp, "%d", isdie); 
	fprintf(fp, "%d", restart);
	fprintf(fp, "%d", leave_trigger);
	fprintf(fp, "%d", apple_trigger);
	fprintf(fp, "%d", apple_trigger2);

	fprintf(fp, "%d", treeleave_vy);
	fprintf(fp, "%d", apple_vy);
	fprintf(fp, "%d", boss_trigger);
	fprintf(fp, "%d", boss_x);
	fprintf(fp, "%d", boss_y);
	fprintf(fp, "%d", bossmouth);
	fprintf(fp, "%d", bosshigh);
	fprintf(fp, "%d", countdown);
	fprintf(fp, "%d", frequency);
	fprintf(fp, "%d", frequency1);
	fprintf(fp, "%d", order);
	fprintf(fp, "%d", order1);
	fprintf(fp, "%d", applelen);
	fprintf(fp, "%d", applehigh);//新增变量
	int k;
	for (k = 0; k < applenum; k++)
	{
		fprintf(fp, "%d", appear[k]);
		fprintf(fp, "%d", appear1[k]);
		fprintf(fp, "%d", bouncetrigger[10]);
	}
	for (k = 0; k < applenum; k++)
	{
		fprintf(fp, "%d", bossapple_vy[k]);
		fprintf(fp, "%d", bossapple1_vy[k]);
		fprintf(fp, "%d", bossapple_x[k]);
		fprintf(fp, "%d", bossapple1_x[k]);
		fprintf(fp, "%d", bossapple_y[k]);
		fprintf(fp, "%d", bossapple1_y[k]);
		fprintf(fp, "%d", bossapple_vx[k]);
	}
	fprintf(fp, "%d", circulateswitch);
	fprintf(fp, "%d", count2);
	fprintf(fp, "%d%d", bigtrunk_x, bigtrunk_y);
	fprintf(fp, "%d%d", bigtrunklen, bigtrunkhigh);
	fprintf(fp, "%d", iapple);
	fprintf(fp, "%d%d", midtrunk_x, midtrunk_y);
	fprintf(fp, "%d%d", midtrunklen, midtrunkhigh);
	
	fprintf(fp, "%d", applecount);
	fprintf(fp, "%d", appletri);
	fprintf(fp, "%d%d", point_x, point_y);
	fprintf(fp, "%d", point_vy);

}

//读取存档
void readrecordfile()//读档
{
	FILE*fp;
	/*fp = fopen_s(&fp,"D:\\1大作业\\gameRecord.txt", "r");*/
	fp = fopen("gameRecord.txt", "r");
	fscanf_s(fp, "%d%d", &i, &j);
	fscanf_s(fp, "%d", &direction);
	fscanf_s(fp, "%d", &input[0]);
	fscanf_s(fp, "%d", &input[1]);
	fscanf_s(fp, "%d%d", &man_x, &man_y);
	fscanf_s(fp, "%d", &grass_zy);
	fscanf_s(fp, "%d", &g);
	fscanf_s(fp, "%d", &man_vy);
	fscanf_s(fp, "%d%d", &step_x, &step_y);
	fscanf_s(fp, "%d", &count);
	fscanf_s(fp, "%d%d", &treeleave1_x, &treeleave1_y);
	fscanf_s(fp, "%d%d", &treeleave2_x, &treeleave2_y);
	fscanf_s(fp, "%d%d", &apple_x, &apple_y);

	fscanf_s(fp, "%d", &manlen);
	fscanf_s(fp, "%d", &manhigh);


	fscanf_s(fp, "%d", &treetlen);
	fscanf_s(fp, "%d", &treethigh);
	fscanf_s(fp, "%d", &treellen);
	fscanf_s(fp, "%d", &treelhigh);
	fscanf_s(fp, "%d", &treedeadline);
	fscanf_s(fp, "%d", &appledeadline);
	fscanf_s(fp, "%d", &trunk2_x);
	fscanf_s(fp, "%d", &trunk2_y);
	fscanf_s(fp, "%d", &trunk1_x);
	fscanf_s(fp, "%d", &trunk1_y);
	fscanf_s(fp, "%d", &isdie);
	fscanf_s(fp, "%d", &restart);
	fscanf_s(fp, "%d", &leave_trigger);
	fscanf_s(fp, "%d", &apple_trigger);
	fscanf_s(fp, "%d", &apple_trigger2);

	fscanf_s(fp, "%d", &treeleave_vy);
	fscanf_s(fp, "%d", &apple_vy);
	fscanf_s(fp, "%d", &boss_trigger);
	fscanf_s(fp, "%d", &boss_x);
	fscanf_s(fp, "%d", &boss_y);
	fscanf_s(fp, "%d", &bossmouth);
	fscanf_s(fp, "%d", &bosshigh);
	fscanf_s(fp, "%d", &countdown);
	fscanf_s(fp, "%d", &frequency);
	fscanf_s(fp, "%d", &frequency1);
	fscanf_s(fp, "%d", &order);
	fscanf_s(fp, "%d", &order1);
	fscanf_s(fp, "%d", &applelen);
	fscanf_s(fp, "%d", &applehigh);//新增变量
	int k;
	for (k = 0; k < applenum; k++)
	{
		fscanf_s(fp, "%d", &appear[k]);
		fscanf_s(fp, "%d", &appear1[k]);
		fscanf_s(fp, "%d", &bouncetrigger[10]);
	}
	for (k = 0; k < applenum; k++)
	{
		fscanf_s(fp, "%d", &bossapple_vy[k]);
		fscanf_s(fp, "%d", &bossapple1_vy[k]);
		fscanf_s(fp, "%d", &bossapple_x[k]);
		fscanf_s(fp, "%d", &bossapple1_x[k]);
		fscanf_s(fp, "%d", &bossapple_y[k]);
		fscanf_s(fp, "%d", &bossapple1_y[k]);
		fscanf_s(fp, "%d", &bossapple_vx[k]);
	}
	fscanf_s(fp, "%d", &circulateswitch);
	fscanf_s(fp, "%d", &count2);
	fscanf_s(fp, "%d%d", &bigtrunk_x, &bigtrunk_y);
	fscanf_s(fp, "%d%d", &bigtrunklen, &bigtrunkhigh);
	fscanf_s(fp, "%d", &iapple);
	fscanf_s(fp, "%d%d", &midtrunk_x, &midtrunk_y);
	fscanf_s(fp, "%d%d", &midtrunklen, &midtrunkhigh);

	fscanf_s(fp, "%d", &applecount);
	fscanf_s(fp, "%d", &appletri);
	fscanf_s(fp, "%d%d", &point_x, &point_y);
	fscanf_s(fp, "%d", &point_vy);
}

void choosestartup();
void startup()
{
	treetlen = 65;
	treethigh = 104;//500-104=396,396-109=287
	treellen = 130;
	treelhigh = 109;
	treetlen = 65;
	treethigh = 104;
	treedeadline = 50;
	appledeadline = 40;

	treeleave2_x = 700;
	treeleave2_y = 287;//暂定
	trunk2_x = 730;
	trunk2_y = 396;

	bigtrunk_x = 730;
	bigtrunk_y = 292;//396-104;
	bigtrunklen = 65;
	bigtrunkhigh = 208;//2*trunk;

	midtrunk_x = 730;
	midtrunk_y = 344;//396-104;
	midtrunklen = 65;
	midtrunkhigh = 156;//2*trunk;

	treeleave1_x = 200;
	treeleave1_y = 287;//暂定
	trunk1_x = 230;
	trunk1_y = 396;

	apple_x = 250;
	apple_y = 300;
	direction = 0;//0==right,1==left,-1=stable
	man_x = 100;
	man_y = 470;//人物初始坐标
	g = 6;
	man_vy = 0;
	manlen = 30;
	manhigh = 30;//人物长宽
	grass_zy = 500;
	step_y = 30;//
	step_x = 20;
	count = 0;
	//passcount = 0;
	//Interface = 1;
	isdie = 0;
	input[0] = 0;
	input[1] = 0;
	restart = 0;
	leave_trigger = 0;
	apple_trigger = 0;
	apple_trigger2 = 0;
	i = 0;
	j = 0;
	treeleave_vy = 0;
	apple_vy = 0;
	boss_trigger = 0;
	boss_x = 700;
	boss_y = 100;

	bossmouth = 200;
	bosshigh = 50;


	countdown = 0;
	frequency = 0;
	order = 0;
	appear[10] = { 0 };
	bossapple_vy[10] = { 0 };
	applelen = 25;
	applehigh = 25;
	bouncetrigger[10] = { 0 };
	appear[10] = { 0 };
	frequency1 = 0;
	order1 = 0;
	bossapple1_vy[10] = { 0 };
	count2 = 0;
	iapple = 0;
	int k;
	for (k = 0; k < 10; k++)
	{
		bossapple_x[k] = 2000;
		bossapple_y[k] = 0;//放在地图外面
		bossapple1_x[k] = 2000;
		bossapple1_y[k] = 0;
	}
	circulateswitch = 0;
	sun_x = 800;
	sun_y = 20;
	sunlen = 290;
	sunhigh = 200;
	applecount = 0;
	for (k = 0; k < 10; k++)
	{
		bossapple_vx[k] = 10;
	}
	//*********************************
	point_x = 1050;
	point_y = 438;
	/*point_vy = 0;*/
	initgraph(1100, 560);//划重点

	//*************************************
	loadimage(&Baron_Nashor, _T("D:\\1大作业\\纳什男爵.jpg"));
	loadimage(&Baron_Nashorb, _T("‪D:\\1大作业\\纳什男爵1b_mask.bmp"));
	loadimage(&background, _T("D:\\1大作业\\choose.jpg"));
	loadimage(&man1[0][0], _T("D:\\1大作业\\kid1.png"));
	loadimage(&man1[0][1], _T("D:\\1大作业\\kid3.png"));//50*50
	loadimage(&man1[0][2], _T("D:\\1大作业\\kid4.png"));
	loadimage(&man1[0][3], _T("D:\\1大作业\\kid5.png"));//50*50
	loadimage(&man2[0][0], _T("D:\\1大作业\\kid1_back.bmp"));
	loadimage(&man2[0][1], _T("D:\\1大作业\\kid3_back.bmp"));//50*50
	loadimage(&man2[0][2], _T("D:\\1大作业\\kid4_back.bmp"));
	loadimage(&man2[0][3], _T("D:\\1大作业\\kid5_back.bmp"));
	//50*50************
	loadimage(&man1[1][0], _T("D:\\1大作业\\lman1.png"));
	loadimage(&man1[1][1], _T("D:\\1大作业\\lman2.png"));//50*50
	loadimage(&man1[1][2], _T("D:\\1大作业\\lman3.png"));
	loadimage(&man1[1][3], _T("D:\\1大作业\\lman4.png"));//50*50*****1345
	loadimage(&man2[1][0], _T("D:\\1大作业\\blman1.jpg"));
	loadimage(&man2[1][1], _T("D:\\1大作业\\blman2.jpg"));//50*50
	loadimage(&man2[1][2], _T("D:\\1大作业\\blman3.jpg"));
	loadimage(&man2[1][3], _T("D:\\1大作业\\blman4.jpg"));
	//50*50
	loadimage(&grass, _T("D:\\1大作业\\地_副本.jpg"));//550*60
	loadimage(&GAMEOVER, _T("D:\\1大作业\\结束_副本.png"));
	loadimage(&apple1, _T("D:\\1大作业\\苹果1.png"));
	loadimage(&apple1_b, _T("D:\\1大作业\\苹果b.bmp"));
	loadimage(&tree2, _T("D:\\1大作业\\树.png"));
	loadimage(&tree2_b, _T("D:\\1大作业\\树_back_mask.bmp"));

	loadimage(&tree1, _T("D:\\1大作业\\树.png"));
	loadimage(&tree1_b, _T("D:\\1大作业\\树_back_mask.bmp"));
	loadimage(&trunk1, _T("D:\\1大作业\\树干.png"));//待补全
	loadimage(&trunk2, _T("D:\\1大作业\\树干.png"));//待补全

	loadimage(&bigtrunk, _T("D:\\1大作业\\大树干4.png"));//待补全
	loadimage(&midtrunk, _T("D:\\1大作业\\中树干.png"));//待补全
	//loadimage(&trunk1, _T("D:\\1大作业\\树干.png"));//待补全
	//************     帅哥   ********************
	//********                   ****
	loadimage(&BOSS, _T("‪D:\\1大作业\\帅哥.jpg"));
	/*loadimage(&sun, _T("‪D:\\1大作业\\太阳1.jpg"));
	loadimage(&sun_b, _T("‪D:\\1大作业\\太阳1b.bmp"));*/
	choosestartup();//开始选择界面的初始化
	//BeginBatchDraw();
	//boss的小苹果
	loadimage(&bossapple1[0][0], _T("D:\\1大作业\\苹果1.png"));
	loadimage(&bossapple1[1][0], _T("D:\\1大作业\\苹果1.png"));//50*50
	loadimage(&bossapple1[2][0], _T("D:\\1大作业\\苹果1.png"));
	loadimage(&bossapple1[3][0], _T("D:\\1大作业\\苹果1.png"));//50*50*****1345
	loadimage(&bossapple1[4][0], _T("D:\\1大作业\\苹果1.png"));
	loadimage(&bossapple1[5][0], _T("D:\\1大作业\\苹果1.png"));//50*50
	loadimage(&bossapple1[6][0], _T("D:\\1大作业\\苹果1.png"));
	loadimage(&bossapple1[7][0], _T("D:\\1大作业\\苹果1.png"));
	loadimage(&bossapple1[8][0], _T("D:\\1大作业\\苹果1.png"));
	loadimage(&bossapple1[9][0], _T("D:\\1大作业\\苹果1.png"));

	loadimage(&bossapple_b1[0][0], _T("D:\\1大作业\\苹果b.bmp"));
	loadimage(&bossapple_b1[1][0], _T("D:\\1大作业\\苹果b.bmp"));//50*50
	loadimage(&bossapple_b1[2][0], _T("D:\\1大作业\\苹果b.bmp"));
	loadimage(&bossapple_b1[3][0], _T("D:\\1大作业\\苹果b.bmp"));//50*50*****1345
	loadimage(&bossapple_b1[4][0], _T("D:\\1大作业\\苹果b.bmp"));
	loadimage(&bossapple_b1[5][0], _T("D:\\1大作业\\苹果b.bmp"));//50*50
	loadimage(&bossapple_b1[6][0], _T("D:\\1大作业\\苹果b.bmp"));
	loadimage(&bossapple_b1[7][0], _T("D:\\1大作业\\苹果b.bmp"));
	loadimage(&bossapple_b1[8][0], _T("D:\\1大作业\\苹果b.bmp"));
	loadimage(&bossapple_b1[9][0], _T("D:\\1大作业\\苹果b.bmp"));

	loadimage(&bossapple1[0][1], _T("D:\\1大作业\\苹果190.png"));
	loadimage(&bossapple1[1][1], _T("D:\\1大作业\\苹果190.png"));//50*50
	loadimage(&bossapple1[2][1], _T("D:\\1大作业\\苹果190.png"));
	loadimage(&bossapple1[3][1], _T("D:\\1大作业\\苹果190.png"));//50*50*****1345
	loadimage(&bossapple1[4][1], _T("D:\\1大作业\\苹果190.png"));
	loadimage(&bossapple1[5][1], _T("D:\\1大作业\\苹果190.png"));//50*50
	loadimage(&bossapple1[6][1], _T("D:\\1大作业\\苹果190.png"));
	loadimage(&bossapple1[7][1], _T("D:\\1大作业\\苹果190.png"));
	loadimage(&bossapple1[8][1], _T("D:\\1大作业\\苹果190.png"));
	loadimage(&bossapple1[9][1], _T("D:\\1大作业\\苹果190.png"));

	loadimage(&bossapple_b1[0][1], _T("D:\\1大作业\\苹果b90.jpg"));
	loadimage(&bossapple_b1[1][1], _T("D:\\1大作业\\苹果b90.jpg"));//50*50
	loadimage(&bossapple_b1[2][1], _T("D:\\1大作业\\苹果b90.jpg"));
	loadimage(&bossapple_b1[3][1], _T("D:\\1大作业\\苹果b90.jpg"));//50*50*****1345
	loadimage(&bossapple_b1[4][1], _T("D:\\1大作业\\苹果b90.jpg"));
	loadimage(&bossapple_b1[5][1], _T("D:\\1大作业\\苹果b90.jpg"));//50*50
	loadimage(&bossapple_b1[6][1], _T("D:\\1大作业\\苹果b90.jpg"));
	loadimage(&bossapple_b1[7][1], _T("D:\\1大作业\\苹果b90.jpg"));
	loadimage(&bossapple_b1[8][1], _T("D:\\1大作业\\苹果b90.jpg"));
	loadimage(&bossapple_b1[9][1], _T("D:\\1大作业\\苹果b90.jpg"));
	//**********************
	loadimage(&bossapple1[0][2], _T("D:\\1大作业\\苹果1180.png"));
	loadimage(&bossapple1[1][2], _T("D:\\1大作业\\苹果1180.png"));//50*50
	loadimage(&bossapple1[2][2], _T("D:\\1大作业\\苹果1180.png"));
	loadimage(&bossapple1[3][2], _T("D:\\1大作业\\苹果1180.png"));//50*50*****1345
	loadimage(&bossapple1[4][2], _T("D:\\1大作业\\苹果1180.png"));
	loadimage(&bossapple1[5][2], _T("D:\\1大作业\\苹果1180.png"));//50*50
	loadimage(&bossapple1[6][2], _T("D:\\1大作业\\苹果1180.png"));
	loadimage(&bossapple1[7][2], _T("D:\\1大作业\\苹果1180.png"));
	loadimage(&bossapple1[8][2], _T("D:\\1大作业\\苹果1180.png"));
	loadimage(&bossapple1[9][2], _T("D:\\1大作业\\苹果1180.png"));

	loadimage(&bossapple_b1[0][2], _T("D:\\1大作业\\苹果b180.jpg"));
	loadimage(&bossapple_b1[1][2], _T("D:\\1大作业\\苹果b180.jpg"));//50*50
	loadimage(&bossapple_b1[2][2], _T("D:\\1大作业\\苹果b180.jpg"));
	loadimage(&bossapple_b1[3][2], _T("D:\\1大作业\\苹果b180.jpg"));//50*50*****1345
	loadimage(&bossapple_b1[4][2], _T("D:\\1大作业\\苹果b180.jpg"));
	loadimage(&bossapple_b1[5][2], _T("D:\\1大作业\\苹果b180.jpg"));//50*50
	loadimage(&bossapple_b1[6][2], _T("D:\\1大作业\\苹果b180.jpg"));
	loadimage(&bossapple_b1[7][2], _T("D:\\1大作业\\苹果b180.jpg"));
	loadimage(&bossapple_b1[8][2], _T("D:\\1大作业\\苹果b180.jpg"));
	loadimage(&bossapple_b1[9][2], _T("D:\\1大作业\\苹果b180.jpg"));
	//*************************************
	loadimage(&bossapple1[0][3], _T("D:\\1大作业\\苹果1270.png"));
	loadimage(&bossapple1[1][3], _T("D:\\1大作业\\苹果1270.png"));//50*50
	loadimage(&bossapple1[2][3], _T("D:\\1大作业\\苹果1270.png"));
	loadimage(&bossapple1[3][3], _T("D:\\1大作业\\苹果1270.png"));//50*50*****1345
	loadimage(&bossapple1[4][3], _T("D:\\1大作业\\苹果1270.png"));
	loadimage(&bossapple1[5][3], _T("D:\\1大作业\\苹果1270.png"));//50*50
	loadimage(&bossapple1[6][3], _T("D:\\1大作业\\苹果1270.png"));
	loadimage(&bossapple1[7][3], _T("D:\\1大作业\\苹果1270.png"));
	loadimage(&bossapple1[8][3], _T("D:\\1大作业\\苹果1270.png"));
	loadimage(&bossapple1[9][3], _T("D:\\1大作业\\苹果1270.png"));

	loadimage(&bossapple_b1[0][3], _T("D:\\1大作业\\苹果b270.jpg"));
	loadimage(&bossapple_b1[1][3], _T("D:\\1大作业\\苹果b270.jpg"));//50*50
	loadimage(&bossapple_b1[2][3], _T("D:\\1大作业\\苹果b270.jpg"));
	loadimage(&bossapple_b1[3][3], _T("D:\\1大作业\\苹果b270.jpg"));//50*50*****1345
	loadimage(&bossapple_b1[4][3], _T("D:\\1大作业\\苹果b270.jpg"));
	loadimage(&bossapple_b1[5][3], _T("D:\\1大作业\\苹果b270.jpg"));//50*50
	loadimage(&bossapple_b1[6][3], _T("D:\\1大作业\\苹果b270.jpg"));
	loadimage(&bossapple_b1[7][3], _T("D:\\1大作业\\苹果b270.jpg"));
	loadimage(&bossapple_b1[8][3], _T("D:\\1大作业\\苹果b270.jpg"));
	loadimage(&bossapple_b1[9][3], _T("D:\\1大作业\\苹果b270.jpg"));

	loadimage(&bossapple[0], _T("D:\\1大作业\\苹果1.png"));
	loadimage(&bossapple[1], _T("D:\\1大作业\\苹果1.png"));//50*50
	loadimage(&bossapple[2], _T("D:\\1大作业\\苹果1.png"));
	loadimage(&bossapple[3], _T("D:\\1大作业\\苹果1.png"));//50*50*****1345
	loadimage(&bossapple[4], _T("D:\\1大作业\\苹果1.png"));
	loadimage(&bossapple[5], _T("D:\\1大作业\\苹果1.png"));//50*50
	loadimage(&bossapple[6], _T("D:\\1大作业\\苹果1.png"));
	loadimage(&bossapple[7], _T("D:\\1大作业\\苹果1.png"));
	loadimage(&bossapple[8], _T("D:\\1大作业\\苹果1.png"));
	loadimage(&bossapple[9], _T("D:\\1大作业\\苹果1.png"));

	loadimage(&bossapple_b[0], _T("D:\\1大作业\\苹果b.bmp"));
	loadimage(&bossapple_b[1], _T("D:\\1大作业\\苹果b.bmp"));//50*50
	loadimage(&bossapple_b[2], _T("D:\\1大作业\\苹果b.bmp"));
	loadimage(&bossapple_b[3], _T("D:\\1大作业\\苹果b.bmp"));//50*50*****1345
	loadimage(&bossapple_b[4], _T("D:\\1大作业\\苹果b.bmp"));
	loadimage(&bossapple_b[5], _T("D:\\1大作业\\苹果b.bmp"));//50*50
	loadimage(&bossapple_b[6], _T("D:\\1大作业\\苹果b.bmp"));
	loadimage(&bossapple_b[7], _T("D:\\1大作业\\苹果b.bmp"));
	loadimage(&bossapple_b[8], _T("D:\\1大作业\\苹果b.bmp"));
	loadimage(&bossapple_b[9], _T("D:\\1大作业\\苹果b.bmp"));

	loadimage(&warning1, _T("D:\\1大作业\\warning1.png"));
	loadimage(&warning2, _T("D:\\1大作业\\warning2_mask.bmp"));
	loadimage(&midapple, _T("D:\\1大作业\\苹果1+50.png"));
	loadimage(&midapple_b, _T("D:\\1大作业\\苹果b+50.jpg"));
	loadimage(&bigapple, _T("D:\\1大作业\\苹果1+100.png"));
	loadimage(&bigapple_b, _T("D:\\1大作业\\苹果b+100.jpg"));
	loadimage(&largeapple, _T("D:\\1大作业\\苹果1+180.png"));
	loadimage(&largeapple_b, _T("D:\\1大作业\\苹果b+180.jpg"));

	loadimage(&stab, _T("D:\\1大作业\\刺.png"));
	loadimage(&stab_b, _T("D:\\1大作业\\刺.jpg"));

	loadimage(&archivepoint, _T("D:\\1大作业\\存档点.png"));

	loadimage(&horizontaltrunk, _T("D:\\1大作业\\横树干.png"));


	BeginBatchDraw();

	/*mciSendString(_T("open D:\\1大作业\\background.mp3 alias mymusic"), NULL, 0, NULL);
	mciSendString(_T("play mymusic"), NULL, 0, NULL);*/

}
void variable_change()
{
	if (man_y + manhigh < grass_zy)
	{
		

		man_vy += g;
		man_y += man_vy;
		while (man_y + man_vy + manhigh > grass_zy)
		{
			man_vy -= 10;
		}

	}
	else
	{
		man_vy = 0;
		count = 0;
	}
	
	
}
void show()
{
	
	putimage(0, 0, &background);
	putimage(0, 500, &grass);
	putimage(550, 500, &grass);//若要对草进行改动,比如裂开，则另设变量，否则可以用number
	
		//第一棵树
	putimage(treeleave1_x, treeleave1_y, &tree1_b, NOTSRCERASE);//树叶及遮罩,遮罩放上边
	putimage(treeleave1_x, treeleave1_y, &tree1, SRCINVERT);

	putimage(trunk1_x, trunk1_y, &trunk1_b);//树干及遮罩
	putimage(trunk1_x, trunk2_y, &trunk1);
	putimage(point_x, point_y, &archivepoint);
	
	//putimage(0, 0, &sun_b, NOTSRCERASE);//sun
	//putimage(0, 0, &sun, SRCINVERT);


	//第二棵树
	putimage(treeleave2_x, treeleave2_y, &tree2_b, NOTSRCERASE);//树叶及遮罩,遮罩放上边
	putimage(treeleave2_x, treeleave2_y, &tree2, SRCINVERT);
	if (!boss_trigger)
	{
		putimage(trunk2_x, trunk2_y, &trunk2_b, NOTSRCERASE);//树干及遮罩
		putimage(trunk2_x, trunk2_y, &trunk2, SRCINVERT);
	}
	putimage(boss_x, boss_y, &BOSS);
	if (boss_trigger)
	{
		
		if (man_x <= 500)
		{
			putimage(450, 450, &stab_b, NOTSRCERASE);//树干及遮罩
			putimage(450, 450, &stab, SRCINVERT);
		}
		if (man_x <= apple_x + applelen)
		{
			appletri = 1;
		}
		if (appletri)
		{
			applecount++;
		}
		if (apple_x < 800)
		{
			if (applecount <= 3)
			{
				putimage(apple_x, apple_y, &apple1_b, NOTSRCERASE);//苹果及遮罩
				putimage(apple_x, apple_y, &apple1, SRCINVERT);
			}
			if (applecount >= 3)
			{
				putimage(apple_x - 50, apple_y + 50, &midapple_b, NOTSRCERASE);//苹果及遮罩
				putimage(apple_x - 50, apple_y + 50, &midapple, SRCINVERT);
			}
			else if (applecount >= 6)
			{
				putimage(apple_x - 100, apple_y + 100, &bigapple_b, NOTSRCERASE);//苹果及遮罩
				putimage(apple_x - 100, apple_y + 100, &bigapple, SRCINVERT);
			}
		}
		else if (apple_x >= 800)
		{
			putimage(apple_x - 155, apple_y + 155, &largeapple_b, NOTSRCERASE);//苹果及遮罩
			putimage(apple_x -155, apple_y + 155, &largeapple, SRCINVERT);
		}
		
		countdown++;
		if (count2 < 3)
		{
			if (countdown >= 5)
			{
				putimage(midtrunk_x, midtrunk_y, &midtrunk);
			}
			if (countdown >= 10)
			{
				putimage(bigtrunk_x, bigtrunk_y, &bigtrunk);//大树干及遮罩
			}
		}
		else
		{
			putimage(bigtrunk_x, 435, &horizontaltrunk);
		}


		if (countdown < 50)
		{
			putimage(boss_x, boss_y, &warning1, NOTSRCERASE);//sign及遮罩
			putimage(boss_x, boss_y, &warning2, SRCINVERT);
		}
		//countdown++;
		if (countdown >= 50)
		{
			putimage(boss_x, boss_y, &Baron_Nashorb, NOTSRCERASE);
			putimage(boss_x, boss_y, &Baron_Nashor, SRCINVERT);
		}
			
		
		//倒计时，用于控制苹果出现时间

		if (countdown >= 100)
		{
			int q;


			frequency++;
			if (frequency == 8)
			{

				order++;

				//bossapple_x[order] = boss_x + bossmouth;
				bossapple_x[order] = boss_x + 60;
				bossapple_y[order] = boss_y + bosshigh;
				appear[order] = 1;
				frequency = 0;

			}
			for (q = 0; q < applenum; q++)
			{
				putimage(bossapple_x[q], bossapple_y[q], &bossapple_b[q], NOTSRCERASE);
				putimage(bossapple_x[q], bossapple_y[q], &bossapple[q], SRCINVERT);


			}


		}
		if (bossapple_x[9] + 25 < 0)
		{

			circulateswitch = 1;

		}
		if (circulateswitch&&count2 < 1)
		{

			//*****  *** ***   ******  ****  ****
			frequency1++;
			if (frequency1 == 8)
			{
				bossapple1_x[order1] = boss_x + 60;
				bossapple1_y[order1] = boss_y + bosshigh;
				appear1[order1] = 1;
				frequency1 = 0;
				order1++;

				//bossapple_x[order] = boss_x + bossmouth;


			}
			int q;
			for (q = 0; q < applenum; q++)
			{
				putimage(bossapple1_x[q], bossapple1_y[q], &bossapple_b1[q][iapple], NOTSRCERASE);
				putimage(bossapple1_x[q], bossapple1_y[q], &bossapple1[q][iapple], SRCINVERT);


			}
			iapple++;
			if (iapple >= 3)
				iapple = 0;

		}
		//这段要优化
		if (countdown >= 330)
		{
			countdown = 50;
			order = 0;
			appear[10] = { 0 };
			circulateswitch = 0;
			frequency = 0;
			int k;
			for (k = 0; k < 10; k++)
			{
				bossapple_x[k] = 2000;
				bossapple_y[k] = 0;
				bossapple1_x[k] = 2000;
				bossapple1_y[k] = 0;
				bossapple_vy[k] = 0;
			}
			count2++;
		}
	}

	if (input[1] || input[0])
	{
		if (direction == 0)//0==right,1==left.i=right,j=left
		{
			putimage(man_x, man_y, &man2[direction][i], NOTSRCERASE);//right
			putimage(man_x, man_y, &man1[direction][i], SRCINVERT);
			i++;
			if (i > 4)
				i = 0;
		}
		else if (direction == 1)
		{
			putimage(man_x, man_y, &man2[direction][j], NOTSRCERASE);//left
			putimage(man_x, man_y, &man1[direction][j], SRCINVERT);
			j++;
			if (j > 4)
				j = 0;
		}
		if (input[1] && !input[0])
		{
			i = 0;
		}
		else if (input[0] && !input[1])
		{
			j = 0;
		}
	}
	
	if (!input[0] && !input[1])
	{
		putimage(man_x, man_y, &man2[direction][0], NOTSRCERASE);
		putimage(man_x, man_y, &man1[direction][0], SRCINVERT);
	}
	input[0] = 0;
	input[1] = 0;
	
	Sleep(50);
	FlushBatchDraw();
}


void move()
{
	if (GetAsyncKeyState(VK_LEFT) & 0x8000)
	{
		man_x -= step_x;//a
		direction = 1;
		input[0] = 0;
		input[1] = 1;
		if (boss_trigger)
		{
			if (count2 <= 3)
			{
				if (man_y > bigtrunk_y && man_y <= 500 && man_x > bigtrunk_x)//微调跳跃高度
				{
					if (man_x - step_x < bigtrunk_x + treetlen)
					{
						man_x += step_x;
					}
				}
			}
			

		}

	}
	if ((GetAsyncKeyState(VK_RIGHT) & 0x8000)) // d asVK_LSHIFT  VK_SPACE
	{
		
			if (man_x + step_x <= 1070)
			{
				man_x += step_x;
			}
			else if (man_x + step_x > 1070)
			{
				if (count2 > 3)
				{
					man_x = step_x;
				}
				
			}
			
		direction = 0;
		input[0] = 1;
		input[1] = 0;
		if (boss_trigger)
		{
			if (count2 < 3)
			{
				if (man_y > bigtrunk_y && man_y <= 500 && man_x < bigtrunk_x)
				{
					if (man_x + step_x > bigtrunk_x)
					{
						man_x -= step_x;
					}
				}
			}
			


		}
		



	}
	if ((GetAsyncKeyState(VK_SPACE) & 0x8000) && (count < 3))// 上方向键
	{
		count++;
		man_vy -= step_y / 2;
		man_y += man_vy / 2;
		
	}
	if ((GetAsyncKeyState(VK_DOWN) & 0x8000))// 上方向键
	{
		if (man_x < point_x+50 && man_x>point_x)
		{
			writerecordfile();
		}
	}


}
void ifafterdie();
void statetest()//状态检测,死了就是isdie==1
{
	//通用模块，改变量名即可
	//if (man_x+manlen > treeleave_x&&man_x<treeleave_x+treellen)//让人不可能被砸到屁股
	//{
	//	if (treeleave_y + treelhigh > man_y&&treeleave_y < man_y + manhigh)
	//	{
	//		isdie = 1;
	//	}
	//	
	//	else
	//		isdie = 0;
	//}
	//if (man_x + manlen >apple_x&&man_x <apple_x + applelen)//让人不可能被砸到屁股
	//{
	//	if (apple_y + applehigh > man_y&&apple_y < man_y + manhigh)
	//	{
	//		isdie = 1;
	//	}

	//	else
	//		isdie = 0;
	//}

	//int q;
	//for (q = 0; q < applenum; q++)
	//{
	//	if (man_x + manlen > bossapple_x[q] && man_x < bossapple_x[q] + applelen)//让人不可能被砸到屁股
	//	{
	//		if (bossapple_y[q] + applehigh > man_y&&bossapple_y[q] < man_y + manhigh)
	//		{
	//			isdie = 1;
	//		}

	//		else
	//			isdie = 0;
	//	}
	//}
}
int expfunc(int a, int b)
{
	int q;
	for (q=0; q < a; q++)
	{
		b *= b;
	}
	return b;
}

void updatewithout()//控制地图元素
{
	
	/*if (count2<3 && man_x>point_x - 50)
	{
		pointcount++;
	}
	if (pointcount == 1)
	{
		point_vy = 40;
	}*/
	//人物坐标与树叶相等触发树叶掉落
	if (man_x == treeleave2_x)
	{
		leave_trigger = 1;
		apple_trigger = 1;

	}
	//树叶掉落
	if (leave_trigger)
	{
		treeleave_vy += g;
		treeleave2_y += treeleave_vy;
	}
	//树叶掉到地上开始向人物移动
	if (treeleave2_y >= 391)
	{
		leave_trigger = 0;
		treeleave2_x -= 50;
	}
	//触发左侧苹果掉落
	if (apple_trigger&&man_x < apple_x + applelen)
	{
		apple_trigger2 = 1;

	}
	//左侧苹果掉落
	if (apple_trigger2)
	{//***
		apple_vy += g;
		if (apple_x < 800)
		{


			if (apple_y + apple_vy >= 375)
			{
				apple_y = 375;
			}
			else
			{
				apple_y += apple_vy;
			}

			if (apple_y >= 375)
			{
				apple_vy = -apple_vy;
			}
		}
		
		else
		{

			if (apple_y + apple_vy >= 200)
			{
				apple_y = 200;
			}
			else
			{
				apple_y += apple_vy;
			}

			if (apple_y >= 200)
			{
				apple_vy = -apple_vy;
			}
		}
		if (apple_vy == 0)
		{
			apple_x += 20;
		}

		

	}

	//树叶离开屏幕
	if (treeleave2_x + treellen <= 0)
	{
		boss_trigger = 1;
	}
	//触发boss
	//boss扔的苹果
	if (boss_trigger)
	{
		if (man_x > 500&&count2<3)//减速带
		{
			man_x -= 18;
		}
		int a;
		for (a = 0; a < applenum; a++)
		{
			if (appear[a])
			{

				if (count2 < 2)
				{

					bossapple_vy[a] += g + 2 * expfunc(count2, -1);//随着波数变化而变化
					if (bossapple_y[a] + bossapple_vy[a] > 475)
					{
						bossapple_y[a] = 475;
					}
					else
					{
						bossapple_y[a] += bossapple_vy[a];
					}


					if (bossapple_y[a] >= 475)
					{
						bouncetrigger[a] = 1;
						bossapple_vy[a] = -bossapple_vy[a];
					}
					if (bouncetrigger[a])
					{
						bossapple_x[a] -= 10;
					}
				}
				else
				{
					bossapple_vy[a] += g + 2 * expfunc(count2, -1);//随着波数变化而变化
					bossapple_x[a] -= bossapple_vx[a];
					if (bossapple_y[a] + bossapple_vy[a] > 475)
					{
						bossapple_y[a] = 475;
					}
					else
					{
						bossapple_y[a] += bossapple_vy[a];
					}


					if (bossapple_y[a] >= 475)
					{
						bouncetrigger[a] = 1;
						bossapple_vy[a] = -bossapple_vy[a];
					}
					/*if (bouncetrigger[a])
					{
						bossapple_x[a] -= 10;
					}*/
				}

			} //
			//******  ****** ******  ********** ****  ***********  ****************  ***********
			if (circulateswitch)
			{
				bouncetrigger[a] = 0;
				appear[a] = 0;

				if (appear1[a])
				{
					bossapple1_vy[a] += g;
					if (bossapple1_y[a] + bossapple1_vy[a] > 475)
					{
						bossapple1_y[a] = 475;
					}
					else
					{
						bossapple1_y[a] += bossapple1_vy[a];
					}
					if (bossapple1_y[a] >= 475)
					{
						bossapple1_x[a] -= 20;
						bossapple1_vy[a] = 0;
					}
				}
			}
		}

	}
	//关于苹果子弹，设置数组，循环发射，当i=n，将i置回0，
}
void gameover()
{
	EndBatchDraw();
	_getch();
	closegraph();
}

void execution()//执行函数
{
	while (1)
	{
		statetest();
		if (isdie)
		{
			restart = 1;
			break;
		}

		variable_change();
		show();
		move();
		updatewithout();
	}
	if (restart)
	{
		ifafterdie();
	}
	//gameover();//考虑要不要分离
}

void choosestartup()
{
	startstick_x = 100;
	startstick_y = 450;
	startblock_x = 80;
	startblock_y = 80;
	choosenum = 0;
	loadimage(&choosebk, _T("D:\\1大作业\\choose.jpg"));
	loadimage(&choosestick, _T("D:\\1大作业\\存档刺.png"));//放置刺的图片
	loadimage(&chooseblock, _T("D:\\1大作业\\存档块.png"));//放置块的图片
}
void inputselect()//将开始界面的用户输入封装
{

	if (GetAsyncKeyState(VK_LEFT) & 0x8000)
	{
		choosenum--;
		if (choosenum <= -1)
		{
			choosenum = 3;
		}
	}

	if (GetAsyncKeyState(VK_RIGHT) & 0x8000)
	{
		choosenum++;
		if (choosenum >= 3)
		{
			choosenum = 0;
		}
	}
	if (GetAsyncKeyState(VK_SHIFT) & 0x8000)
	{
		if (choosenum == 0)
			execution();
		if (choosenum == 1)
		{
			readrecordfile();
			execution();
		}


	}
	//*************************************************************
	//*********                存档框架                 *****************
	//*********************************************     ************


}
void startchoose()//主要函数
{
	//choosestartup();
	//int choosenum = 0;//考虑要不要在开头定义，做全局变量并且保存，这里暂时定义在函数中初始化,没设全局可能有问题
	while (1)//can change
	{
		putimage(0, 0, &choosebk);
		//putimage();//必须要背景盖掉图片！！！
		if (choosenum == 0)
		{
			putimage(startstick_x, startstick_y, &choosestick);
		}
		if (choosenum == 1)
		{
			putimage(startstick_x + 300, startstick_y, &choosestick);
		}
		if (choosenum == 2)
		{
			putimage(startstick_x + 600, startstick_y, &choosestick);
		}

		putimage(startblock_x, startblock_y, &chooseblock);//注意存档内容
		putimage(startblock_x + 300, startblock_y, &chooseblock);
		putimage(startblock_x + 600, startblock_y, &chooseblock);

		FlushBatchDraw();
		inputselect();
	}
}
void ifafterdie()
{

	while (1)
	{
		putimage(0, 0, &GAMEOVER);
		isdie = 0;//重置,原因是刷新了一帧后又复原，导致没有任何效果
		if (GetAsyncKeyState(VK_TAB) & 0x8000)
		{

			break;
		}
	}
	startup();
	startchoose();
	//gameover();
	//closegraph();

}


int main()
{
	startup();
	startchoose();
	gameover();
}//树叶滚动，碰撞检测
